/**
 * 拿到每个页面按钮的配置
 *
 *  * ##BUTTON命名:
 * create:新增, check:查看/详情， edit:编辑， config:配置， publish:发布/推送,  查询:query
 * copy:一键复制／复制，  changeStatus:更改状态,  import:导入/匹配
 * distrbute:分配权限, delete:删除, add:新增角色,  export:导出，
 * top:置顶  save:保存
 *
 * **/

export default {
  state: {
    buttonConfig: {}
  },
  getters: {
    getButtonConfigAll: (state) => {
      return state.buttonConfig
    },
    getButtonConfig: (state, getters) => (router) => {
        // console.log('getters: getButtonConfig => ', state.buttonConfig, router, state.buttonConfig[router])
      return state.buttonConfig[router]
    }
  },
  mutations: {
    setButtonConfig (state, info) {
        // console.warn('setButtonConfig', info.router, info)
      let menuLv1 = info && info.children ? info.children : null;
      if (!menuLv1) return;
      let target = {};
      for (let i = 0; i < menuLv1.length; i++) {
        let buttons = menuLv1[i] && menuLv1[i].buttons ? menuLv1[i].buttons : null;
        let obj = {};
        for (let j = 0; j < buttons.length; j++) {
          obj[buttons[j]] = true;
        }
        target[menuLv1[i].router] = obj;
        state.buttonConfig = Object.assign({}, state.buttonConfig, target)
      }
    }
  },
  actions: {
    dispatchMenu (context, data) {
      for (let i = 0; i < data.length; i++) {
        context.commit('setButtonConfig', data[i])
      }
    }
  }
}
